from multiprocessing import Process
import re
from DrissionPage import ChromiumPage
import time

from loguru import logger
import pandas as pd

from service import update_nwp_data

# 创建页面对象，并启动或接管浏览器
page = ChromiumPage()
# 跳转到登录页面


def open_home():
    home_tab = page.get_tab(title="Home")
    if home_tab is None:
        page.get('https://supermind.10jqka.com.cn/notebook/user/565286428/tree')
        time.sleep(2)

def open_task_page(title):
    nwp_tab = page.get_tab(title=title)
    if nwp_tab:
        return nwp_tab
    els = page.eles(".list_item row")

    for item in els:
        link = item.ele("tag:a")
        if link and title in link.text:
            print(link)
            table = link.click.for_new_tab()
            table["股票代码"] = table["股票代码"].apply(
                        lambda x: re.findall(r"\b\d{6}\b", x)[0]
                    )
            return table

def get_task_data(nwp_tab):
    dataframe = nwp_tab.ele("tag:table")
    table_data =  pd.read_html(dataframe.html)
    table = None
    if table_data:
        table = table_data[0]
    return table



# open_home()
# nwp_tab = open_task_page("内外盘比")
# data = get_task_data(nwp_tab)
# columns = data.columns.tolist()
# for col in columns:
#     if "外盘" in col and "内盘" in col:
#         print(col)


# update_nwp_data()
def test():
    print(1234)
if __name__ == "__main__":

    task = Process(target=test)
    task.start()